<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
pageContext.setAttribute("contextPath", path);
%>

<!DOCTYPE html>

<html>
  <head>
    <title>登录-股市日记</title>

	<meta http-equiv="description" content="登录页面">
	<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0">
	
	<jsp:include page="/core/tool/resources.jsp"></jsp:include>
	<script src="${contextPath}/core/jquery/jquery.md5.js"></script>
	
	<script>
		var _win=frame.window.top();
		if(_win!=window){
			_win.location.href=window.location.href; 
			_win.location.reload; 
		}
	</script>
	<style type="text/css">
		.box{
    		display: flex;
   	 		justify-content: center;
   	 		align-items: center;
   	 		height:100%;
   	 		margin:0;
		}
		html,body{
			height:100%;
			margin:0;
		}
	</style>
	
  </head>
  
  <body class="box">  
	<div class="easyui-panel" title="用户登录" style="width:320px;padding:10px 40px 20px 40px;">
	
		<div style="margin-bottom:10px">
			<input id="userName" name="userName" class="easyui-textbox" style="width:100%;height:40px;padding:12px"
				data-options="prompt:'Username',iconCls:'icon-man',iconWidth:38, required:true, validType:'length[1,20]'">
		</div>
		<div style="margin-bottom:20px">
			<input id="userPwd" name="userPwd" class="easyui-textbox" type="password" style="width:100%;height:40px;padding:12px"
				data-options="prompt:'Password',iconCls:'icon-lock',iconWidth:38, required:true, validType:'length[1,20]'">
		</div>
			
		<form id="form1" name="form1"  class="easyui-form" method="post" data-options="novalidate:true,ajax:false">
			<input id="hiddenUserName" type="hidden" name="userName"/>
			<input id="hiddenUserPwd" type="hidden" name="userPwd"/>
			<div style="margin-bottom:20px">
				<input type="checkbox" name="remPwd" checked="checked"><span style="font-size:14px;">自动登录(一周)</span>
			</div>
			<div>
				<a  class="easyui-linkbutton" onClick="doLogin()" data-options="iconCls:'icon-ok'" style="padding:5px 0px;width:48%;">
				 	<span style="font-size:14px;">Login</span>
				</a>
				<a  class="easyui-linkbutton" data-options="iconCls:'icon-add'" style="padding:5px 0px;width:48%"
					href="${contextPath}/base/login/register.jsp">
				 	<span style="font-size:14px;">Register</span>
				</a>
			</div>
		</form>
		
	</div>
</body>
</html>

<script type="text/javascript">

	var md5Password;

	$(function(){
		var usrName = $.cookie("userName");
		md5Password = $.cookie("userPwd");
		if(usrName){
			$("#userName").textbox("setValue",usrName);
			$("#userPwd").textbox("setValue","password");
		}
	});

	function doLogin() {
		var valitrue=$("#form1").form('enableValidation').form('validate');
		if(valitrue){
			var userName = $("#userName").val();
			var password = $("#userPwd").val();
			if (password != "password") {
				md5Password = $.md5(password);
				$.cookie("userName",userName);
				$.cookie("userPwd",md5Password);
			}
			$("#hiddenUserName").val(userName);
			$("#hiddenUserPwd").val(md5Password);
			document.form1.action="${contextPath}/base/login/login.do";
			document.form1.submit();
		}
	}
</script>
